/*
 * Copyright 2021 Alibaba Group Holding Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.graphscope.communication;

import static com.alibaba.graphscope.utils.CppClassName.GRAPE_COMMUNICATOR;
import static com.alibaba.graphscope.utils.CppHeaderName.CORE_JAVA_JAVA_MESSAGES_H;
import static com.alibaba.graphscope.utils.CppHeaderName.GRAPE_COMMUNICATOR_H;
import static com.alibaba.graphscope.utils.JNILibraryName.JNI_LIBRARY_NAME;

import com.alibaba.fastffi.CXXHead;
import com.alibaba.fastffi.CXXReference;
import com.alibaba.fastffi.FFIConst;
import com.alibaba.fastffi.FFIGen;
import com.alibaba.fastffi.FFINameAlias;
import com.alibaba.fastffi.FFIPointer;
import com.alibaba.fastffi.FFITypeAlias;

/**
 * The java wrapper for <a
 * href="https://github.com/alibaba/libgrape-lite/blob/master/grape/communication/communicator.h">grape
 * Communicator class</a>, which provides some useful aggregators. Shall not be used by user.
 *
 * <p>For User-defined msg types, the corrsponding code is generated by graphscope-processor.
 */
@FFIGen(library = JNI_LIBRARY_NAME)
@CXXHead(GRAPE_COMMUNICATOR_H)
@CXXHead(CORE_JAVA_JAVA_MESSAGES_H)
@FFITypeAlias(GRAPE_COMMUNICATOR)
public interface FFICommunicator extends FFIPointer {

    @FFINameAlias("Sum")
    <MSG_T> void sum(@FFIConst @CXXReference MSG_T msgIn, @CXXReference MSG_T msgOut);

    @FFINameAlias("Min")
    <MSG_T> void min(@FFIConst @CXXReference MSG_T msgIn, @CXXReference MSG_T msgOut);

    @FFINameAlias("Max")
    <MSG_T> void max(@FFIConst @CXXReference MSG_T msgIn, @CXXReference MSG_T msgOut);

    @FFINameAlias("SendTo")
    <MST_T> void sendTo(int dstFid, @FFIConst @CXXReference MST_T msgOut);

    @FFINameAlias("RecvFrom")
    <MSG_T> void receiveFrom(int srcFid, @CXXReference MSG_T msgIn);
}
